package qc.module.platform.api.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import qc.common.core.exception.QCPromptException;
import qc.module.platform.dto.phone.OfficialCategoryDto;
import qc.module.platform.service.OfficialCategoryService;

import java.util.List;

/**
 * @projectName: qcdp
 * @package: qc.module.platform.api.controller
 * @className: QcOfficialPhoneController
 * @version: 1.0
 */
@RestController
@RequestMapping("/officialcategory")
public class OfficialCategoryController {

    private OfficialCategoryService service;

    @Autowired
    public void setOfficialCategoryService(OfficialCategoryService service) {
        this.service = service;
    }

    //是否为逻辑删除，为true表示逻辑删除--修改记录标记，为false表示物理删除--从数据库表中删除记录
    private static final boolean isLogicDelete = false;

    /**
     * 新增号码分类
     *
     * @param dto: 新增分类信息
     * @return String 分类信息成功返回null，失败返回错误信息
     * @author QcCheng Tech
     * @date 2023/9/28
     */
    @RequestMapping(value = "/add", method = {RequestMethod.GET, RequestMethod.POST})
    public String add(@RequestBody OfficialCategoryDto dto) {
        return service.add(dto);
    }


    /**
     * 修改号码分类信息
     *
     * @param dto: 修改分类信息
     * @return String 修改分类信息成功返回null，失败返回错误信息
     * @author QcCheng Tech
     * @date 2023/9/28
     */
    @RequestMapping(value = "/update", method = {RequestMethod.PUT, RequestMethod.POST})
    public String update(@RequestBody OfficialCategoryDto dto) {
        return service.update(dto);
    }


    /**
     * 按id删除指定电话分类.
     *
     * @param id: 公务电话分类id
     * @author QcCheng Tech
     * @date 2023/9/28
     */
    @RequestMapping(value = "/delete", method = {RequestMethod.DELETE})
    public String deleteByParam(@RequestParam int id) throws QCPromptException {
        return service.delete(id, isLogicDelete);
    }

    /**
     * 按id删除指定公务电话分类.
     *
     * @param id: 公务电话分类id
     * @author QcCheng Tech
     * @date 2023/9/28
     */
    @RequestMapping(value = "/delete/{id}", method = {RequestMethod.DELETE})
    public String deleteByPath(@PathVariable(required = true) int id) throws QCPromptException {
        return service.delete(id, isLogicDelete);
    }


    /**
     * 根据id查询公务电话分类信息
     *
     * @param id: 公务号码分类id
     * @return OfficialCategoryDto 公务号码分类信息
     * @author QcCheng Tech
     * @date 2023/9/28
     */
    @RequestMapping(value = "/get", method = {RequestMethod.GET})
    public OfficialCategoryDto getByParam(@RequestParam Integer id) throws QCPromptException {
        return service.get(id);
    }


    /**
     * 根据id查询公务电话分类信息
     *
     * @param id: 公务号码分类id不能为空
     * @return OfficialCategoryDto 公务号码分类信息
     * @author QcCheng Tech
     * @date 2023/9/28
     */
    @RequestMapping(value = "/get/{id}", method = {RequestMethod.GET})
    public OfficialCategoryDto getByPath(@PathVariable Integer id) throws QCPromptException {
        return service.get(id);
    }

    /**
     * 获取全部分类信息
     *
     * @return List<OfficialCategoryDto> 分类信息查询结果
     * @author QcCheng Tech
     * @date 2023/10/7
     */
    @RequestMapping(value = "/all", method = {RequestMethod.GET})
    public List<OfficialCategoryDto> getAll() {
        return service.getAll();
    }
}
